package com.andryu.opengl

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.os.bundleOf
import androidx.navigation.findNavController
import androidx.recyclerview.widget.LinearLayoutManager
import com.andryu.base.adapter.LearnListAdapter
import com.andryu.base.constant.CommonConstants
import com.andryu.base.entity.LearnListEntity
import com.andryu.base.ui.fragment.BaseFragment
import com.andryu.opengl.databinding.FragmentOpenglPageBinding
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject
import javax.inject.Named

@AndroidEntryPoint
class OpenglPageFragment : BaseFragment() {

    private var _binding: FragmentOpenglPageBinding?= null
    private val binding get() = _binding!!

    @Inject
    @Named("OpenglList")
    lateinit var mDataList: MutableList<LearnListEntity>
    private lateinit var mAdapter: LearnListAdapter

    override fun onCreateView(
        inflater: LayoutInflater, container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View {
        _binding = FragmentOpenglPageBinding.inflate(inflater, container, false)
        return binding.root
    }

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        binding.rvOpengl.layoutManager = LinearLayoutManager(context)
        mAdapter = LearnListAdapter(mDataList)
        binding.rvOpengl.adapter = mAdapter
        mAdapter.setOnItemClick {
            val bundle = bundleOf(CommonConstants.NAVI_FRAGMENT_LEARN_ENTITY to it)
            binding.rvOpengl.findNavController().navigate(R.id.opengl_surface, bundle)
        }
    }


    override fun onDestroy() {
        super.onDestroy()
        _binding = null
    }
}